$(function(){

    $("#myform").validate({
        rules: {
            username:{
                required:true,
                isusername:true
            },
            passworld:{
                required:true,
                ispassworld:true
            },
            passworld_:{
                required:true,
                equalTo:"#passworld"
            },
            phone:{
                required:true,
                isphone:true
            }
        },
        messages: {
            username:{
                required:'请输入用户名',
            },
            passworld:{
                required:'请输入密码',
            },
            passworld_:{
                required:'请再次输入密码',
                equalTo:"两次密码不一致"
            },
            phone:{
                required:'请输入电话',
            }
        }
    })

    jQuery.validator.addMethod("isusername", function(value, element) {   
        var tel = /^[a-zA-Z0-9_]{5,16}$/;
        return this.optional(element) || (tel.test(value));
    }, "请输入5-16位字符");
    jQuery.validator.addMethod("ispassworld", function(value, element) {   
        var tel = /^[A-Z][a-z][a-zA-Z0-9]{6,16}$/;
        return this.optional(element) || (tel.test(value));
    }, "请输入开头包含大和小写两位字符,包括数字,字母的8-16位密码");
    jQuery.validator.addMethod("isphone", function(value, element) {   
        var tel = /^[1][3-9][0-9]{9}$/;
        return this.optional(element) || (tel.test(value));
    }, "请输入正确的手机号码");

})